package com.reebake.ideal.system;

import com.reebake.ideal.jdbc.FlywayUtil;
import org.flywaydb.core.Flyway;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@ComponentScan(basePackageClasses = SystemBasicAutoConfiguration.class)
@Configuration
public class SystemBasicAutoConfiguration {
    @Bean
    MapperScannerConfigurer workMapperScannerConfigurer() {
        MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
        mapperScannerConfigurer.setBasePackage(SystemBasicAutoConfiguration.class.getPackageName() + ".mapper");
        return mapperScannerConfigurer;
    }

    @Bean
    Flyway systemBasicFlyway(DataSource dataSource) {
        String schema = "system";
        return FlywayUtil.migrate(dataSource, schema);
    }
}
